//1002.查找共用字符
//https://leetcode.cn/problems/find-common-characters/description/
class Solution {
public:
    vector<string> commonChars(vector<string>& words) {
        int arr[26]; //存放每一个字符串筛选出的字符数最小计数(缓冲区)
        int minarr[26]; //存放最终所有字符串的最小计数
        memset(minarr, 127, sizeof(minarr)); //将每一个int设置为最大值
        for (const auto& s : words)
        {
            memset(arr, 0, sizeof(arr)); //重置缓冲区
            for (const auto& c : s)
                ++arr[c - 'a'];

            for (int i = 0; i < 26; ++i)
                minarr[i] = min(minarr[i], arr[i]); //求每个字母计数的最小值
        }

        vector<string> vs;
        for (int i = 0; i < 26; ++i)
            if (minarr[i])
            {
                for (int k = 0; k < minarr[i]; ++k)
                    vs.push_back(string(1, i + 'a'));
            }

        return vs;
    }
};